GFile *repo_file;
char *head_ref_path;
char *objects_path;
+ char *config_path;
gboolean inited;
char *current_head;
+
+ GKeyFile *config;
};
static void
g_clear_object (&priv->repo_file);
g_free (priv->head_ref_path);
g_free (priv->objects_path);
+ g_free (priv->config_path);
g_free (priv->current_head);
+ if (priv->config)
+ g_key_file_free (priv->config);
G_OBJECT_CLASS (ostree_repo_parent_class)->finalize (object);
}
priv->head_ref_path = g_build_filename (priv->path, "HEAD", NULL);
priv->objects_path = g_build_filename (priv->path, "objects", NULL);
+ priv->config_path = g_build_filename (priv->path, "config", NULL);
return object;
}
ostree_repo_check (OstreeRepo *self, GError **error)
{
OstreeRepoPrivate *priv = GET_PRIVATE (self);
+ gboolean ret = FALSE;
+ char *version = NULL;;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Couldn't find objects directory '%s'", priv->objects_path);
- return FALSE;
+ goto out;
}
- priv->inited = TRUE;
+ if (!parse_checksum_file (self, priv->head_ref_path, &priv->current_head, error))
+ goto out;
+
+ priv->config = g_key_file_new ();
+ if (!g_key_file_load_from_file (priv->config, priv->config_path, 0, error))
+ {
+ g_prefix_error (error, "Couldn't parse config file: ");
+ goto out;
+ }
+
+ version = g_key_file_get_value (priv->config, "core", "repo_version", error);
+ if (!version)
+ goto out;
- return parse_checksum_file (self, priv->head_ref_path, &priv->current_head, error);
+ if (strcmp (version, "0") != 0)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid repository version '%s'", version);
+ goto out;
+ }
+
+ priv->inited = TRUE;
+
+ ret = TRUE;
+ out:
+ g_free (version);
+ return ret;
}
static gboolean
{ NULL }
};
+#define DEFAULT_CONFIG_CONTENTS ("[core]\n" \
+ "repo_version=0\n")
+
+
gboolean
ostree_builtin_init (int argc, char **argv, const char *prefix, GError **error)
{
gboolean ret = FALSE;
char *otdir_path = NULL;
char *objects_path = NULL;
+ char *config_path = NULL;
GFile *otdir = NULL;
GFile *objects_dir = NULL;
+ GFile *configf = NULL;
context = g_option_context_new ("- Initialize a new empty repository");
g_option_context_add_main_entries (context, options, NULL);
objects_dir = g_file_new_for_path (objects_path);
if (!g_file_make_directory (objects_dir, NULL, error))
goto out;
+
+ config_path = g_build_filename (repo_path, "config", NULL);
+ configf = g_file_new_for_path (config_path);
+
+ if (!g_file_replace_contents (configf,
+ DEFAULT_CONFIG_CONTENTS,
+ strlen (DEFAULT_CONFIG_CONTENTS),
+ NULL, FALSE, 0, NULL,
+ NULL, error))
+ goto out;
ret = TRUE;
out:
if (context)
g_option_context_free (context);
g_free (otdir_path);
+ g_free (objects_path);
+ g_free (config_path);
g_clear_object (&otdir);
+ g_clear_object (&objects_dir);
+ g_clear_object (&configf);
return ret;
}